﻿<UserControl
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:KinectToMidi="clr-namespace:KinectToMidi.Views"
             xmlns:Toolkit="clr-namespace:Microsoft.Kinect.Toolkit;assembly=Microsoft.Kinect.Toolkit"
             xmlns:kt="clr-namespace:Microsoft.Samples.Kinect.WpfViewers;assembly=Microsoft.Samples.Kinect.WpfViewers" 
             xmlns:ViewModels="clr-namespace:KinectToMidi.ViewModels" 
             xmlns:properties="clr-namespace:KinectToMidi.Properties"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" 
        xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" x:Name="userControl"
        x:Class="KinectToMidi.Views.MainView"
        mc:Ignorable="d"
             d:DesignHeight="620" d:DesignWidth="1050">
    <UserControl.Resources>
        <kt:KinectSensorManager x:Key="sensorManager" KinectSensor="{Binding KinectSensorChooser.Kinect, ElementName=SensorChooserUI, Mode=OneWay}" SkeletonStreamEnabled="True" SkeletonTrackingMode="Default"/>
    </UserControl.Resources>
	<i:Interaction.Behaviors>
		<ei:DataStateBehavior Binding="{Binding WarningShowed}" Value="True" TrueState="ErrorShowed" FalseState="ErrorHidden"/>
	</i:Interaction.Behaviors>
    <UserControl.DataContext>
        <Binding Mode="OneWay" Path="Main" Source="{StaticResource ViewModelLocatorDataSource}"/>
    </UserControl.DataContext>

    <Grid x:Name="grid1">
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="ShowErrorStates">
                <VisualState x:Name="ErrorShowed">
                    <Storyboard>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="gridWarning">
                            <EasingDoubleKeyFrame KeyTime="0:0:0.4" Value="20"/>
                        </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="ErrorHidden">
                    <Storyboard>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="gridWarning">
                            <EasingDoubleKeyFrame KeyTime="0:0:0.4" Value="0"/>
                        </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>

        <DockPanel>
            <Menu DockPanel.Dock="Top" IsMainMenu="True">
                <MenuItem Header="{x:Static properties:Resources.File}">
                    <MenuItem Header="{x:Static properties:Resources.Load}" Command="{Binding LoadCommand}"/>
                    <MenuItem Header="{x:Static properties:Resources.Save}" Command="{Binding SaveCommand}"/>
                </MenuItem>
                <MenuItem Header="_Settings" >
                    <StackPanel Orientation="Horizontal">
                        <Label Content="{x:Static properties:Resources.MidiSettingsColon}" VerticalContentAlignment="Center" />
                        <ComboBox Width="200" ItemsSource="{Binding MidiSettingsVM.OutDeviceNames}" SelectedItem="{Binding MidiSettingsVM.CurrentOutDeviceName}"/>
                        <Button Width="20" x:Name="m_btnRefresh" ToolTip="{x:Static properties:Resources.Refresh}" Command="{Binding RefreshMidiDevicesCommand}">
                            <Image Height="16" Source="/KinectToMidi;component/Images/update.ico" Stretch="Fill" Width="16"/>
                        </Button>
                    </StackPanel>
                    <CheckBox Content="_Seat mode" IsChecked="{Binding SeatMode}"></CheckBox>
                </MenuItem>
                <MenuItem Header="{x:Static properties:Resources.View}">
                    <MenuItem Header="{x:Static properties:Resources.ShowKinectWindowTitle}" Command="{Binding ShowVideoWindow, Mode=OneWay}"/>
                </MenuItem>
                <MenuItem Header="{x:Static properties:Resources.Help}">
                    <MenuItem Header="{x:Static properties:Resources.SkeletonMap}" Command="{Binding ShowJointsMap}"/>
                </MenuItem>
            </Menu>

            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="550"/>
                </Grid.ColumnDefinitions>
                <Grid Grid.Column="0" Margin="5,5,5,5">
                    <Toolkit:KinectSensorChooserUI x:Name="SensorChooserUI" IsListening="True" VerticalAlignment="Top" HorizontalAlignment="Center" Height="40" KinectSensorChooser="{Binding Main.SensorChooser, Source={StaticResource ViewModelLocatorDataSource}}" Panel.ZIndex="1000"/>
                    <TextBlock x:Name="m_tbCoordinates" VerticalAlignment="Bottom" HorizontalAlignment="Center" TextAlignment="Right" Text="{Binding RightHandCoordianates, StringFormat=right hand: \{0\}}" Panel.ZIndex="1000"/>

                    <Viewbox Stretch="Fill" HorizontalAlignment="Center" VerticalAlignment="Center">
                        <!-- Make the depthViewer and skeletonViewer overlap entirely. -->
                        <Grid>
                            <kt:KinectDepthViewer 
								x:Name="DepthViewer"
								KinectSensorManager="{Binding Mode=OneWay, Source={StaticResource sensorManager}}"
								DepthTreatment="{Binding DepthTreatment}"
								CollectFrameRate="True" 
								RetainImageOnSensorChange="True"/>
                            <Canvas>
                                <kt:KinectSkeletonViewer 
									KinectSensorManager="{Binding Mode=OneWay, Source={StaticResource sensorManager}}"
									Width="{Binding ActualWidth, ElementName=DepthViewer}"
									Height="{Binding ActualHeight, ElementName=DepthViewer}"
									ShowBones="true" ShowJoints="true" ShowCenter="true" ImageType="Depth" />
                                <Image x:Name="m_img"
									Width="{Binding ActualWidth, ElementName=DepthViewer}"
									Height="{Binding ActualHeight, ElementName=DepthViewer}"/>
                            </Canvas>
                        </Grid>
                    </Viewbox>
                </Grid>
                <Grid Grid.Column="1" Margin="5,5,5,5">
                    <KinectToMidi:ConditionsMappingSetControl/>
                </Grid>
            </Grid>
        </DockPanel>
        <Grid x:Name="gridWarning" VerticalAlignment="Bottom" Height="0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="0.25*"/>
                <ColumnDefinition Width="0.3*"/>
                <ColumnDefinition Width="0.25*"/>
            </Grid.ColumnDefinitions>
            <Border Grid.Column="1" Background="Red" BorderThickness="1,1,1,0" CornerRadius="3">
                <TextBlock Text="{Binding WarningText}" TextAlignment="Center"/>
            </Border>
        </Grid>
    </Grid>
</UserControl>
